package p2;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

public class ServidorFrase extends UnicastRemoteObject implements FraseInterface {
	private static final long serialVersionUID = -2121596542529869876L;

	//	constructor de la clase
	public ServidorFrase() throws RemoteException {
		super();
	}

	//	main del servidor
	public static void main(String args[]) {
		try	{
			ServidorFrase servidor = new ServidorFrase ();
			Naming.rebind( "rmi://localhost/servidor_frase", servidor );
			System.out.println( "Servidor de Frases ..." );
		}
		catch ( Exception e ) { System.out.println(e); }
	}

	public int getNumeroConsonantes(String a){
		int c = 0;
		a = a.toLowerCase();
		for(int i = 0; i < a.length(); i++){
			if(esConsonante(a.charAt(i))) c++;
		}
		return c;
	}
	private boolean esConsonante(char c) {
		if(!esLetra(c)) return false;
		if(!esVocal(c)) return true;
		return false;
	}

	private boolean esVocal(char c) {
		if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u')
			return true;
		return false;
	}

	private boolean esLetra(char c) {
		if(c >= 'a' && c <= 'z')return true;
		return false;
	}

	public int getNumeroLetras(String a) {
		int c = 0;
		a = a.toLowerCase();
		for(int i = 0; i < a.length(); i++){
			if(esLetra(a.charAt(i))) c++;
		}
		return c;
	}
	public int getNumeroPalabras(String a) {
		return a.split(" ").length;
	}
	public int getNumeroVocales(String a) {
		int c = 0;
		a = a.toLowerCase();
		for(int i = 0; i < a.length(); i++){
			if(esVocal(a.charAt(i))) c++;
		}
		return c;
	}
}